/**
 * 
 */
package com.sian.base.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;



/**
 * 登录拦截器
 * @author desert
 * @version 1.0 2014/1/15
 */

public class LoginInterceptor implements HandlerInterceptor{

	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object obj) throws Exception {
		// TODO Auto-generated method stub
		
		HttpSession hsession = request.getSession();
//		String menuId_str = request.getParameter("navid");
//		
//		Object roleLimitMap_obj =  hsession.getAttribute("rolelimitmap");
		
//		if(menuId_str!=null&&menuId_str.length()>0
//				       &&roleLimitMap_obj!=null){
//			
//			Map<Integer,RoleLimit> map = (Map<Integer,RoleLimit>)roleLimitMap_obj;
//			
//			RoleLimit rolelimit_obj = map.get(Integer.valueOf(menuId_str));
//			
//			hsession.setAttribute("rolelimitObj", rolelimit_obj);
//		}
//		
		//如果session中不存在登录的用户信息则 拦截
//		Object existObj = hsession.getAttribute("empinfo");
//		if(existObj==null){
//			return false;
//		}
	String url = request.getRequestURI();
		
//		if(!((url.indexOf("login/validatecode.action")!=-1)||
//				               (url.indexOf("user/login.action")!=-1)||
//				                  (url.indexOf("/login/sessiontimeout.action")!=-1))){
//			
//			//如果session中不存在登录的用户信息则 拦截
//			Object existObj = hsession.getAttribute("user");
//			
//			if(existObj==null){
//				response.sendRedirect(request.getContextPath()+"/pages/error/sessiontime.jsp");
//				return false;
//			}
//		}
		
		return true;
	}

}
